<template>
  <div class="cart">
    <div class="cart-title">
      <div class="item">
        <div class="drop"></div>
        <div class="text">30天无忧退货</div>
      </div>
      <div class="item">
        <div class="drop"></div>
        <div class="text">48小时快速退款</div>
      </div>
      <div class="item">
        <!-- <div class="drop"></div> -->
        <div class="text">满88元免邮费</div>
      </div>
    </div>

    <!-- 单元格 -->
    <van-swipe-cell v-for="item in list" :key="item.id">
      <van-card class="goods-card" />
      <template #default>
        <div class="danyuan">
          <div class="item">
            <div class="l">
              <van-checkbox-group v-model="result">
                <van-checkbox :name="item.id" checked-color="#b4282d" class="puBtn"
                  ></van-checkbox
                >
              </van-checkbox-group>
              <div class="pictu">
                <div class="son">
                  <img :src="item.list_pic_url" alt="" />
                </div>
                <div class="son">
                  <p>{{ item.goods_name }}</p>
                  <p>¥{{ item.retail_price }}</p>
                </div>
              </div>
            </div>
            <div class="r">x1</div>
          </div>
        </div>
      </template>
      <template #right>
        <van-button
          @click="deleteGoods(item.id)"
          square
          text="删除"
          type="danger"
          class="delete-button"
        />
      </template>
    </van-swipe-cell>
    <div class="line2"></div>
    <div class="submit">
      <div class="left">
        <div class="radio" @click="show = !show">
          <div class="icon" :class="show ? 'dis-show' : ''">
            <span class="iconfont icon-duihao"></span>
          </div>
        </div>
        <div class="text">全选</div>
      </div>
      <div class="right">
        <div class="price">¥ 0</div>
        <div class="sub">下单</div>
      </div>
    </div>
    <tab-bar></tab-bar>
  </div>
</template>
<script>
import tabbar from "../../components/tabbar";
import { cartList, deleteAction } from "../../api/cart/index";
export default {
  data() {
    return {
      checked: true,
      show: false,
      list: [],
      result: [],
    };
  },
  methods: {
    // pushBtn(id) {
    //   console.log("000");
    //   var demo = this.result.every((item) => item != id);
    //   if (demo) {
    //     this.result.push(id);
    //   } else {
    //     var i = this.result.findIndex((item) => item == id);
    //     this.result.splice(i, 1);
    //   }
    // },
    deleteGoods(id) {
      deleteAction({ id }).then((res) => {
        console.log(res);
        this.init();
      });
    },
    init() {
      var _this = this;
      cartList({ openId: "15836741268" }).then((res) => {
        console.log(res);
        this.list = res.data;
      });
    },
  },
  mounted() {
    this.init();
  },
  components: {
    "tab-bar": tabbar,
  },
};
</script>
<style lang="scss">
$color1: #b4282d;
.goods-card {
  margin: 0;
  padding: 10px;
  background-color: white;
}
.van-swipe-cell__wrapper {
  transform: translate3d(-80.05px, 0px, 0px);
}
.danyuan {
  height: 83px;
  padding: 10px !important;
  //   padding-top: 20px !important;
  background-color: #fff;
  .item {
    //   background-color: pink;
    color: #000;
    position: relative;
    height: 100%;
    border-bottom: 1px solid #f4f4f4;
    .l {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      left: 0;
      width: fit-content;
      .pictu {
        overflow: hidden;
        margin-left: 20px;
        .son {
          float: left;
          &:nth-child(1) {
            width: 62px;
            height: 62px;
            margin: 0 10px;
            background-color: #f4f4f4;
            img {
              width: 100%;
              height: 100%;
            }
          }
          &:nth-child(2) {
            p {
              margin: 12px 0;
            }
          }
        }
      }
    }
    .r {
      position: absolute;
      right: 13px;
      top: 50%;
      transform: translateY(-50%);
    }
  }
}
.delete-button {
  margin-top: 8px !important;
  height: 96px;
  width: 60px;
}
.puBtn {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}
</style>
<style lang="scss" scoped>
$color1: #b4282d;
* {
  margin: 0;
  padding: 0;
}
.line2 {
  height: 30px;
  background-color: #f4f4f4;
}
.cart {
  height: 100vh;
  background-color: #fff;
  padding-bottom: 100px;
  .cart-title {
    font-size: 12.5px;
    display: flex;
    justify-content: space-between;
    padding: 15px 10px;
    background-color: #f4f4f4;
    .item {
      width: fit-content;
      .text {
        background: url("http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/servicePolicyRed-518d32d74b.png")
          no-repeat center left;
        background-size: 5px 5px;
        padding-left: 7px;
      }
    }
  }
}
.submit {
  position: fixed;
  bottom: 50px;
  left: 0;
  width: 100%;
  height: 48px;
  background-color: #fff;
  .left {
    float: left;
    margin-top: 15px;
    margin-left: 10px;
  }
  .right {
    float: right;
    height: 100%;
    .sub {
      float: left;
      width: 88px;
      height: 100%;
      background-color: $color1;
      text-align: center;
      line-height: 50px;
      font-size: 14.5px;
      color: #fff;
    }
    .price {
      float: left;
      color: $color1;
      height: 100%;
      line-height: 50px;
      margin-right: 20px;
    }
  }
  .radio {
    float: left;
    width: 19px;
    height: 19px;
    border: 1px solid #ccc;
    border-radius: 50%;
    .icon {
      opacity: 0;
      transition: 0.3s;
      width: 20px;
      height: 20px;
      border-radius: 50%;
      background-color: $color1;
      span {
        font-size: 12px;
        color: #fff;
        text-align: center;
        line-height: 20px;
      }
    }
    .icon.dis-show {
      opacity: 1;
    }
  }
  .text {
    float: left;
    line-height: 23px;
    margin-left: 8px;
  }
}
</style>
